package com.example.administrator.oriding.Model;

import android.telecom.Call;

import com.example.administrator.oriding.Listener.RetrofitListener;
import com.example.administrator.oriding.beans.LoginBean;

public class UserModel {
    private LoginService service;
    private Retrofit retrofit;
    private static final String BASE_URL = "http:/172.24.10.175:8080/foodService/";
    public UserModel(){
        retrofit = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
        service = retrofit.create(LoginService.class);

    }
    public void userLogin(String username, String password, final RetrofitListener listener){
        Call call = service.userLogin(username,password);
        Callback<LoginBean> callback = new Callback<LoginBean>() {
            @Override
            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
                listener.onSuccess(response.body(),1);
                System.out.print(response.body().toString());
            }

            @Override
            public void onFailure(Call<LoginBean> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
}
